//============================================================================
// Name        : ex17.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
#include "PointC.h"
#define N 10

int main() {
	ofstream fp("my.txt",ios::out|ios::trunc);
	try {
		if(fp.fail()) throw "Opening fails";
	}
	catch(const char * s){
		cout << s << endl;
		exit(1);
	}
	PointC * p;
	int pMax=N;
	float ran;
	p=new PointC [pMax];
	for(int i=0;i<pMax; i++) {
		ran=(float ) rand()/ (float ) RAND_MAX;
		p[i].setX(ran*10.0);
		p[i].setY(ran*10.0);
		cout << p[i].getX() << " "<< p[i].getY() << endl;
	}
	cout << " Last "<<endl;
	for(int i=0;i<pMax; i++) {
		fp << p[i].getX() << " " << p[i].getY() << endl;
	}

	fp.close();

	fstream fp1("my.txt",ios::in);

	delete [] p;
	p=new PointC [pMax];
	float a,b;
	for(int i=0;i<pMax; i++) {
		fp1>> a >> b ;
		p[i].setX(a);
		p[i].setY(b);
	}

	for(int i=0;i<pMax; i++) {
		cout << p[i].getX() << " "<< p[i].getY() << endl;
	}

	return 0;
}
